package com.laicunba.event.listener;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.laicunba.event.WithdrawEvent;
import com.laicunba.pojo.FinancingTargetBidDO;
import com.laicunba.pojo.WithdrawDO;
import com.laicunba.service.mq.ActiveMQMessageFactory;
import com.laicunba.service.mq.ActiveMQService;

@Component
public class WithdrawListener implements ApplicationListener<WithdrawEvent> {

	@Autowired
	private ActiveMQService activeMQService;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void onApplicationEvent(WithdrawEvent event) {

		if (event.getSource() instanceof FinancingTargetBidDO) {
			FinancingTargetBidDO bidDO = (FinancingTargetBidDO) event.getSource();
			// 发消息
			JSONObject msg = ActiveMQMessageFactory.createBidMessage(bidDO);
			activeMQService.sendTopics("lcb.core.d.payout.post.success", msg.toJSONString());
		} else if (event.getSource() instanceof WithdrawDO) {

			JSONObject msg = ActiveMQMessageFactory.createWithdrawMessage((WithdrawDO) event.getSource());
			activeMQService.sendTopics("lcb.core.h.payout.post.success", msg.toJSONString());
		}

	}

}
